//
//  Radio.swift
//  FM
//
//  Created by x on 2017/8/30.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class Radio: NSObject {
    
    /// 电台ID
    var id:String?
    
    /// 电台作者昵称
    var title:String?
    
    /// 电台的图标地址
    var cover:String? {
        didSet{
            coverImageURL = URL(string: cover!)
        }
    }
    
    var fmnum:String?
    
    /// 用户id
    var user_id:String?
    
    /// 收听数量
    var viewnum:String? {
        didSet {
            let num:Int = Int(viewnum!)!
            collectionNum = "\(num/10000)W"
        }
    }
    
    /// 电台的内容介绍
    var content:String?
    
    /// 电台关注数量(粉丝数)
    var favnum:String?
    
    /// 用户信息
    var user:User?
    
    /// 保存电台图片的URL
    var coverImageURL:URL?
    
    ///保存收藏数量
    var collectionNum:String?
    
    
    /// 快速返回一个数据模型数组
    ///
    /// - Parameter datas: <#datas description#>
    class func analysisData(datas:[[String:AnyObject]]) ->[Radio] {
        var models:[Radio] = [Radio]()
        for dic in datas {
            models.append(Radio(dic: dic))
        }
        
        return models
    }
    
    init(dic:[String: AnyObject]) {
        super.init()
        setValuesForKeys(dic)
    }
    
    override func setValue(_ value: Any?, forKey key: String) {
        super.setValue(value, forKey: key)
        //拦截kvc,给用户赋值  要使用super来赋值
        if "user" == key {
            user = User(dic: value as! [String:AnyObject])
            return
        }
    }
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        print("Radio===key=======\(key)")
    }
    
    /// 打印model数据模型
    override var description: String {
        let keys = ["id","title","cover","fmnum","user_id","viewnum","content","favnum","user"]
        let dic = dictionaryWithValues(forKeys: keys)
        
        return "\(dic)"
    }

}
